import {Actor, Action} from 'iflux2';
import {GoodsSortType} from '../constant/action-type';


export default class GoodsActor extends Actor {
    defaultState() {
        return {
            type: 1,
            goodsList: []
        }
    }


    @Action(GoodsSortType.SET_LIST)
    setGoodsList(state, list) {
        return state.set('goodsList', list);
    }



    @Action('DEL_GOODS')
    delGoods(state, goods) {
        return state.update('goodsList', (goodsList)=>goodsList.filterNot((item)=>{
            if (state.get('type')) {
                return item.get('productId') === goods.get('productId');
            }
            return item.get('goodsId') === goods.get('goodsId');
        }))
    }


    @Action(GoodsSortType.SET_SORT_TYPE)
    setType(state, type) {
        return state.set('type', type);
    }
}
